package com.shuigu.controller;

import com.shuigu.pojo.dto.LoginDto;
import com.shuigu.service.IAuthService;
import com.shuigu.response.ShuiGuResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 认证接口
 */
@RestController
@RequestMapping("auth")
@Slf4j
public class AuthController {

    private final IAuthService authService;

    public AuthController(IAuthService authService) {
        this.authService = authService;
    }

    /**
     * 系统用户登陆
     */
    @PostMapping("sys")
    public ShuiGuResult sysLogin(@RequestBody LoginDto loginDto) {
        String token = authService.login(loginDto);
        if(token != null && !token.isEmpty()) {
            return ShuiGuResult.success().put("token",token);
        }
        return ShuiGuResult.error("认证失败，请重试");
    }

}
